<template>
	<view class="container">
		<m-map-field label="到达地点" type="arrivalAddress" @change="onChange"/>
		<m-date-field label="返回时间" type="backTime" @change="onChange"/>
		<van-field label="乘坐人数"  type="digit" input-align="right" data-type="passengersNum" right-icon="edit" @change="onChange"
		  />
		 
		 <view style="margin: 20px 0;">
		 	<van-button :color="primaryColor" :square="true" size="large" @click="onAddAdress">确认添加</van-button>
		 </view>
		 
		 <van-toast id="van-toast" />
	</view>
</template>

<script>
	import Toast from '@/wxcomponents/toast/toast'
	import utils from '@/common/utils.js'
	export default {
		data() {
			return {
				primaryColor:getApp().globalData.primaryColor,
				reqData: {}
			};
		},
		onLoad(options) {
			this.reqData.orderId = options.orderid
		},
		methods:{
			async onAddAdress(){
				//todo add req
				try{
					if(!this.reqData.arrivalAddress || !this.reqData.backTime || !this.reqData.passengersNum){
						Toast('信息填写不完整，请检查')
						return
					}
					this.reqData.token = uni.getStorageSync('userinfo').token
					await utils.req('/order/addTrip', this.reqData)
					
					uni.navigateBack({
						delta:1
					})
				}catch(e){
					Toast(e.msg)
				}
			},
			onChange(event){
				var type = event.currentTarget.dataset.type
				if(type == 'arrivalAddress'){
					this.reqData.arrivalAddress = event.detail.address
				}else{
					this.reqData[type] = event.detail
				}
			}
		}
		
	}
</script>

<style lang="scss" scoped>
.container{
	padding: 10px 0;
}
</style>
